<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      :row-class-name="tableRowClassName">
      <el-table-column
        prop="id"
        label="编号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址"
        width="180">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
    </el-table>


      <!--  分页插件  -->
      <el-pagination
        align="right"
        background
        layout="prev, pager, next"
        :total="totals"
        :current-page="currentPage"
        :page-size="pageSize"
        @current-change="gotoPage">
      </el-pagination>
  </div>
</template>


<script>
export default {
  name: 'empTa',
  data() {
    return {
      tableData: [],
      totals: 0,
      currentPage: 1,
      pageSize: 5
    }
  },
  methods: {
    gotoPage(curr) {
      this.currentPage = curr;
      this.getUsers()
    },
    getUsers() {
      //调用接口
      let param = {"currentPage": this.currentPage, "pageSize": this.pageSize}
      this.$http.post('/user/list', param)
        .then(res => {
          this.tableData = res.data.data;
          this.totals = res.data.totals
        })
        .catch(res => {
          alert("此处网不同")
        })
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row';
      }else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
  },
  mounted() {
    this.getUsers();
  }
}
</script>

<style>
.el-table .warning-roe {
  background: #42b983;
}

.el-table .warning-roe {
  background: cornflowerblue;
}
</style>

